<!-- 创建人才培养方案 -->
<template>
  <div class="assessment-edit-plan-container">
    <div class="my-form-container" style="margin:0;width:100%;height: 100%">
       <el-form
        :model="tablelist"
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <div style="display:flex">
          <el-form-item class="my-form-item" prop="mc">
            <div class="my-form-item-label">
              名称
              <span class="mustW">*</span>
            </div>
            <el-input v-model="tablelist.mc" style="width:80%" placeholder="请输入名称"></el-input>
          </el-form-item>
          <el-form-item class="my-form-item" prop="bb">
            <div
              class="my-form-item-label"
            > 版本
              <span class="mustW">*</span>
            </div>
            <el-input v-model="tablelist.bb" style="width:80%" placeholder="请输入版本"></el-input>
          </el-form-item>
        </div>
        <div style="display:flex">
          <el-form-item class="my-form-item" prop="syzy">
            <div class="my-form-item-label">
              适用专业
              <span style="color: #ff3819">*</span>
            </div>
            <el-select v-model="tablelist.syzy" placeholder="请选择" class="bk" @input="handleChangeZY" clearable  style="width:80%">
              <el-option
                v-for="(item,index) in syzyList"
                :key="index"
                :label="item.name"
                :value="index"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="my-form-item" prop="pyfafl">
            <div class="my-form-item-label">
              培养方案分类
              <span style="color: #ff3819">*</span>
            </div>
            <el-select v-model="tablelist.pyfafl" placeholder="请选择" class="bk" @input="handleChangePlan" clearable >
              <el-option
                v-for="(item,index) in kcflList"
                :key="index"
                :label="item.flmc"
                :value="index"
              >
              </el-option>
            </el-select>
            <div style="margin: 22px 40px 0 0;position:relative">
              <!-- <el-button type="warning" icon="el-icon-setting" @click="pjByIdGuide">培养方案分类设置</el-button> -->
              <button
                @click="pjByIdGuide"
                style="
                  width: 150px;
                  height: 30px;
                  border: 1px solid #f86900;
                  border-radius: 6px;
                  color: #f86900;
                  background: #fef1e8;
                "
              >
                <img
                  src="../../../assets/assessment/设置.png"
                  style="
                    width: 17px;
                    height: 17px;
                    background-size: 100% 100%;
                    background-repeat: no-repeat;
                    position: absolute;
                    top: 12px;
                    left: 10px;
                  "
                />
                <span style="margin-left:20px">培养方案分类设置</span>
              </button>
            </div>
          </el-form-item>
        </div>
        <div style="display:flex">
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">额定总学分</div>
            <el-input v-model="tablelist.edzxf" placeholder="请输入额定总学分" type="number" style="width: 32%"></el-input>
          </el-form-item>
        </div>
        <div style="display:flex">
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">必修课额定学分</div>
            <el-input v-model="tablelist.bxkedxf" placeholder="请输入必修课额定学分" type="number" style="width:80%"></el-input> 
          </el-form-item>
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">选修课额定学分</div>
            <el-input v-model="tablelist.xxkedxf" placeholder="请输入选修课额定学分" type="number" style="width:80%"></el-input>
          </el-form-item>
        </div>
        <div style="display:flex">
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">自修课额定学分</div>
            <el-input v-model="tablelist.zxkedxf" placeholder="请输入自修课额定学分" type="number" style="width:80%"></el-input>
          </el-form-item>
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">讲座课额定学分</div>
            <el-input v-model="tablelist.jzkedxf" placeholder="请输入讲座课额定学分" type="number" style="width:80%"></el-input>
          </el-form-item>
        </div>
        <div style="display:flex">
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">实践教学额定学分</div>
            <el-input v-model="tablelist.sjjxedxf" placeholder="请输入实践教学额定学分" type="number" style="width:80%"></el-input>
          </el-form-item>
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">教育训练额定学分</div>
            <el-input v-model="tablelist.jyxledxf" placeholder="请输入教育训练额定学分" type="number" style="width:80%"></el-input>
          </el-form-item>
        </div>
        <div style="display:flex">
          <el-form-item class="my-form-item">
            <div class="my-form-item-label">附件</div>
            <!-- <input type="file" ref="inputU" class="import-file" name="file" @change="getFile($event)">   -->
            <el-upload
              class="upload-demo"
              ref="upload"
              action="https://jsonplaceholder.typicode.com/posts/"
              :file-list="fileList"
              :on-change="getFile" 
              :on-exceed="handleExceed"
              :auto-upload="false"
              style="margin: 22px 40px;width: 280px;margin: 22px 40px"
              :limit="1"
            >
              <el-button slot="trigger" style="
                width: 90px;
                height: 30px;
                border:1px solid #5230e9;
                border-radius: 6px;
                color: #5230e9;
                background: #efebff;" size="small" type="primary">选择文件</el-button>
                <!-- <span style="color:red">（最大允许上传个数为1）</span> -->
            </el-upload>
             <!--  <button slot="trigger" style="
                width: 90px;
                height: 30px;
                border:1px solid #5230e9;
                border-radius: 6px;
                color: #5230e9;
                background: #efebff;
              ">选择文件</button><span style="color:red">（最大允许上传个数为1）</span>
            </el-upload> -->
          </el-form-item>
        </div>
        <div style="display:flex;position: relative;">
          <el-form-item class="my-form-item" style="height: 100px">
              <div class="my-form-item-label">说明</div>
              <el-input
                v-model="tablelist.sm"
                placeholder="请输入说明"
                class="zyjs"
                type="textarea"
              ></el-input>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="button-group">
      <div @click="addSubmit">
        <div>保 存</div>
      </div>
      <div @click="cancalS">
        <div>取 消</div>
      </div>
      <!-- <el-button type="success" @click="addSubmit">保 存</el-button>
      <el-button type="danger" @click="cancalS" style="margin-left:60px">取 消</el-button> -->
    </div>
  </div>
</template>

<script>
import {
    reqAddnewTraining,
    getUploadTrain,
    queryFirstcoursetype
  } from "@/api/propositionReview/approval";
import { szzszy } from "@/api/professional/details";

export default {
  data() {
    return {
      syzy: "",
      kcfl: "",
      showYprDialog: false,
      fileName: "",
      tablelist: {
        mc: "",
        bb: "",
        syzy: "",
        syzyid:"",
        pyfafl: "",
        planFlId:"",
        edzxf: "",
        bxkedxf: "",
        xxkedxf: "",
        zxkedxf: "",
        jzkedxf: "",
        sjjxedxf: "",
        jyxledxf: "",
        fj:"",
        sm: "",
      },
      rules: {
        mc: [
          { required: true, message: "请输入名称", trigger: "blur" },
        ],
        bb: [
          { required: true, message: "请输入版本", trigger: "blur" },
        ],
        syzy: [
          { required: true, message: '请选择适用专业', trigger: 'change' }
        ],
        pyfafl: [
          { required: true, message: "请选择培养方案分类", trigger: "change" },
        ]
      },
      syzyList: [],
      kcflList: [],
    };
  },
  mounted() {
    this.getSpecialtyInfo();
    this.getInitInfo();
    // this.getdetail();
    // this.getCreateDId(this.tablelist)
  },
  methods: {
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件`);
    },
    //培养分类方案下拉框
    async getInitInfo() {
      const result = await queryFirstcoursetype();
      if (result.data.code == 200) {
        this.kcflList = result.data.data;
      } else {
        this.$message({ type: "error", message: "培养方案分类获取失败！" });
      }
    },
    //适用专业下拉框
    async getSpecialtyInfo() {
      const result = await szzszy();
      if (result.data.code == 200) {
        this.syzyList = result.data.data;
      } else {
        this.$message({ type: "error", message: "适用专业获取失败！" });
      }
    },
    //选择适用专业事件
    handleChangeZY(index){
      this.tablelist.syzyid = this.syzyList[index].id;
      this.tablelist.syzy = this.syzyList[index].name;
    },
    //选择培养方案事件
    handleChangePlan(index){
      this.tablelist.planFlId = this.kcflList[index].id;
      this.tablelist.pyfafl = this.kcflList[index].flmc;
    },
    // 培养方案分类设置
    pjByIdGuide() {
      this.$router.push({
        path: "/admin/training/classifications", //要跳转的页面的路由
      });
    },
    getFile() {
      this.fileName = this.$refs.upload.uploadFiles[0].raw;
      /* let file = event.target.files;
      this.tablelist.fileName = file[0].name;
      console.log(file[0].name);
      let form = new FormData();
      let id = this.tablelist.id;
      form.append("file", file[0]);
      form.append("id", id);
      let el = this;
      return new Promise(() => {
        getUpload(form).then((res) => {
          if (res.data.code === 200) {
            this.getdetail();
            el.$message({
              showClose: true,
              message: "上传成功",
              type: "success",
            });
          } else {
            el.$message({
              showClose: true,
              message: "上传失败，请重新上传",
              type: "error",
            });
          }
        });
      }); */
    },
    // 保存
    addSubmit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          let fd = new FormData();
          fd.append("file", this.fileName);
          if(this.fileName){
            getUploadTrain('',fd).then((res) => {
              if(res.data.code == 200){
                this.tablelist.fj  = res.data.data;
                let result = null;
                result = reqAddnewTraining(this.tablelist);
                result.then(res =>{
                  if (res.data.code == 200) {
                    this.$message({ type: "success", message: "保存成功！" });
                    this.$refs.ruleForm.resetFields();
                    this.$router.push({
                      path: "/admin/training/trainings", //要跳转的页面的路由
                    });
                    return "ok";
                  }
                })
              }
            });
          } else {
            this.tablelist.fj == '';
            let result = null;
            result = reqAddnewTraining(this.tablelist);
            result.then(res =>{
              if (res.data.code == 200) {
                this.$message({ type: "success", message: "保存成功！" });
                this.$refs.ruleForm.resetFields();
                this.$router.push({
                  path: "/admin/training/trainings", //要跳转的页面的路由
                });
                return "ok";
              }
            })
          }
        } else {
          return false;
        }
      })
    },

    // 取消
    cancalS() {
      this.$router.push({
        path: "/admin/training/trainings", //要跳转的页面的路由
      });
      // this.$refs[ruleForm].resetFields();
    },
  },
};
</script>
<style lang="less" scoped>
/* /deep/.el-input__inner {
  border: none;
} */
/deep/.el-upload-list{
  position: absolute;
  left: 22%;
  top: 25%;
}
/deep/.el-upload-list__item .el-icon-close-tip {
    position: absolute;
    top: 30px;
    right: 52px;
}
 /deep/ .el-form-item__error {
    color: #F56C6C;
    font-size: 12px;
    padding-top: 4px;
    position: absolute;
    top: 75%;
    left: 32%;
  }
.mustW {
  color: red;
}
.bk {
  /deep/ .el-input__inner {
    border-radius: 4px;
    // border: 1px solid #004ca7;
  }
}
.zyjs {
  width: 82% !important;
  margin: 20px auto;
  /deep/ .el-input__inner {
    height: 70px !important;
    border-radius: 4px;
    border: 1px solid #004ca7;
  }
}
.el-input,.el-select {
  width: 80%;
  display: flex;
  justify-items: center;
  align-items: center;
  margin-left: 40px;
  margin-right: 40px;
}
/* .el-input:nth-child(-n+2){
  width: 80%;
} */
.el-select:nth-child(-n+2){
  width: 80%;
}
.my-form-item {
  width: 100%;
  height: 85px;
  border-bottom: 1px solid rgba(0, 76, 167, 0.39);
  margin-bottom: 0;
  > div {
    display: flex;
    height: 100%;
    &:nth-child(2) {
      .my-form-item-label {
        border-left: 1px solid rgba(0, 76, 167, 0.39);
      }
    }
    .my-form-item-label{
      width: 220px;
      padding-left: 60px;
      background: rgba(0, 76, 167, 0.1);
      display: flex;
      flex: none;
      align-items: center;
      color: #004CA7;
      font-size: 16px;
      font-weight: bold;
      border-left: 1px solid rgba(0, 76, 167, 0.39);
      margin-left: -1px;
      .mustW {
        color: red;
      }
    }
    .el-form-item__content{
      display: flex;
    }
  }
}
.el-date-editor {
  width: 38%;
}
.choose-ypr-container {
  width: 100%;
  margin: 0px auto;

  .choose-ypr-search-container {
    .el-input--prefix .el-input__inner {
      padding-left: 30px;
    }

    .el-input__inner {
      &::placeholder {
        color: #b8b8b8;
      }

      &::-webkit-input-placeholder {
        /* WebKit browsers 适配谷歌 */
        color: #b8b8b8;
      }

      &:-moz-placeholder {
        /* Mozilla Firefox 4 to 18 适配火狐 */
        color: #b8b8b8;
      }

      &::-moz-placeholder {
        /* Mozilla Firefox 19+ 适配火狐 */
        color: #b8b8b8;
      }

      &:-ms-input-placeholder {
        /* Internet Explorer 10+  适配ie*/
        color: #b8b8b8;
      }
    }

    display: flex;
    flex-direction: row;
    align-items: center;

    .title {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
      margin-right: 5px;
    }

    .search-button {
      width: 77px;
      height: 28px;
      line-height: 28px;
      background: #f1f8fe;
      border: 1px solid #51aef6;
      border-radius: 6px;
      cursor: pointer;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;

      > span {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #51aef6;
      }

      > img {
        width: 20px;
        height: 20px;
        margin-right: 4px;
      }
    }

    .button-list {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-left: 21px;

      .button-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 69px;
        height: 27px;
        line-height: 27px;
        border: 1px solid #004ca7;
        border-radius: 4px;
        margin-right: 10px;
        text-align: center;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #004ca7;

        .del-icon {
          position: absolute;
          right: 0px;
          top: 0px;
          width: 12px;
          height: 12px;
          padding: 2px;
        }
      }
    }
  }

  .choose-ypr-container .choose-ypr-table-container .el-table__header th {
    padding: 0;
    height: 57px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  /deep/ .el-table .cell {
    color: #004ca7;
  }

  .choose-ypr-table-container {
    margin-top: 30px;

    .el-table td,
    .el-table th.is-leaf,
    .el-table--border,
    .el-table--group {
      border-color: #c7d7eb;
    }

    .el-table__header tr,
    .el-table__header th {
      padding: 0;
      height: 57px;
      background-color: #edf2f9;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
    }

    .el-table__body tr,
    .el-table__body td {
      padding: 0;
      height: 51px;
    }

    .table-data {
      width: 100%;
      border: 0.8px solid #004ca7;
      border-radius: 9px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #004ca7;
    }
  }
}

.assessment-container {
  .el-dialog__body {
    height: 251px;
  }

  .el-dialog__footer {
    padding: 10px 20px 45px;
  }

  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }

  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
    height: 18px;
    width: 18px;
  }

  .el-checkbox__inner::after {
    height: 10px;
    left: 6px;
  }

  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }

  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }

  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }

  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
}

.cz-save {
  box-sizing: border-box;
  line-height: 44px;
  border-radius: 4px;
  font-size: 12px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  text-align: center;
  margin-top: 70px;
  margin-left: 40px;
  display: flex;
  flex-direction: row;
  cursor: pointer;
  align-content: center;
  justify-content: center;
  align-items: center;
}

.jf-save {
  display: flex;
  align-items: center;
  margin-left: 48px;
}

.fileClass {
  position: relative;
  cursor: pointer;

  .save {
    width: 120px;
    height: 50px;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    color: #fff;
    background: #303133;
  }
}

.my-form-item-value {
  font-size: 16px;
  color: #004ca7;
  height: 100%;
  flex: 1;
  line-height: 60px;
  padding-left: 38px;
  display: flex;
  align-items: center;
}

.assessment-edit-plan-container {
  .assessment-design {
    .el-textarea__inner {
      resize: none;
      font-size: 16px;
      color: rgba(0, 76, 167, 1);
    }
  }
}
</style>
<style scoped lang="less">
.assessment-edit-plan-container {
  .assessment-design {
    padding: 25px 38px !important;
  }

  .button-group {
    cursor: pointer;
    margin-top: 50px;
    text-align: center;

    > div {
      display: inline-block;
      font-size: 18px;
      padding: 6px 22px;
      border-radius: 6px;

      &:nth-child(1) {
        color: #f3b815;
        border: 1px solid #f3b815;
        background: #fff6ef;
        margin-right: 139px;
      }

      &:nth-child(2) {
        color: #ff3819;
        border: 1px solid #ff3819;
        background: #ffefef;
      }
    }
  }
}
</style>
